function [best_is, opt_profits, EYI,EYin, ProfitPart]=prop_policy(j_all, N)
%if_j_all_paper==1时，表示使用论文的病人的病种
addpath functions;
global P J I ci cI r LAMBDA CURRENT PIEs EYin ProfitPart EYI S
patient_number = size(j_all, 2);
N = min(patient_number,N);%N不能超过给了病种的病人数。
ProfitPart = zeros(3, N);
EYI = zeros(1,N);
EYin = zeros(1,N);
S = zeros(I, J);
Line = j_all;
best_is = zeros(1, N);
opt_profits = zeros(1, N);

for n = 1:N

    % fprintf("Arranging Patient No. %d \n", n);
    % start_time = ftimer(); % set loop clock
    CURRENT = n;
    j = Line(n);
    profits = zeros(1, I);
    for i = 1:I
        S_test = S;
        S_test(i, j) = S_test(i, j) + 1; % Replace rim & rimS
        Q = findQ(S_test); % size(Q) = [I, CURRENT]
        R = findR(Q);
        profits(i) = function_fQR(Q, R);
    end
    % return;
    i = find(profits == max(profits));
    best_is(n) = i(1);
    i = i(1);
    S(i, j) = S(i, j) + 1;
    Q = findQ(S);
    R = findR(Q);
    opt_profits(n) = profits(i);
end
return